home *** CD-ROM | disk | FTP | other *** search
- function loadActivity(fname)
- {
- t = getTimer();
- ai.load(fname);
- }
- function setActivityInfo(_ai)
- {
- ai = _ai;
- render();
- return true;
- }
- function render()
- {
- delete this.answerList;
- this.answerList = new Array();
- layoutInfo.qTextFormat.align = "left";
- if(parseInt(ai.type.text) == master.activityTypes.MULTI)
- {
- this.isMulti = true;
- }
- clearClip();
- var tableY = layoutInfo.box.y;
- var rightSideBuffer = layoutInfo.rightSideBuffer;
- var topBuffer = 0;
- if(ai.videoFile)
- {
- tableY = layoutInfo.temp4InstY;
- topBuffer = master.videoPlayer._height;
- rightSideBuffer = 250;
- }
- else if(ai.artFile)
- {
- rightSideBuffer = 250;
- }
- trace(this + ".render: called");
- var title_mc;
- var inst_mc;
- if(ai.titleSpanish)
- {
- title_mc = createTitleField(ai.titleSpanish);
- title_mc._x = layoutInfo.box.x;
- title_mc._y = layoutInfo.box.y + topBuffer;
- tableY = title_mc._y + title_mc._height;
- }
- if(ai.instructionsEnglish || ai.instructionsSpanish)
- {
- inst_mc = this.createInstructionField(this,"inst",ai.instructionsEnglish);
- inst_mc._x = layoutInfo.box.x;
- inst_mc._y = title_mc == null ? tableY : title_mc._y + title_mc._height;
- trace("INST Y: " + inst_mc._y);
- tableY = inst_mc._y + inst_mc._height;
- trace("tableY (first check): " + tableY);
- }
- if(ai.videoFile == null && _parent.actNumber_mc._height > inst_mc._height + title_mc._height)
- {
- tableY = _parent.actNumber_mc._y + _parent.actNumber_mc._height + 10;
- }
- tableY = tableY != 0 ? tableY : layoutInfo.box.y;
- trace("tableY: " + (tableY + topBuffer));
- trace("rightSideBuffer: " + rightSideBuffer);
- table = new TableClass(this);
- tables = new Array();
- atables = new Array();
- if(!(ai.questions.question instanceof Array))
- {
- var tempa = new Array();
- tempa.push(ai.questions.question);
- ai.questions.question = tempa;
- }
- var qlen = ai.questions.question.length;
- var qtc;
- var qtr;
- var answerChoices;
- var answerText;
- var question;
- var answer;
- var checkbox;
- var feedbackCheck;
- var mcon;
- var i = 0;
- while(i < qlen)
- {
- mcon = this.createEmptyMovieClip("qcon" + i,5000 + i);
- var questionText;
- var answerText1;
- var answerText2;
- questionText = ai.questions.question[i].questionText.text;
- question = createQuestionField(mcon,i,replaceBlanks(questionText,8));
- tables[i] = new TableClass();
- qtc = new TableCell(question);
- qtr = new TableRow();
- qtr.addCell(qtc);
- tables[i].addRow(qtr);
- atables[i] = new TableClass();
- answerChoices = ai.questions.question[i].answerChoice;
- var j = 0;
- while(j < answerChoices.length)
- {
- answerText = answerChoices[j];
- feedbackCheck = mcon.attachMovie("check","correctcheck_" + i + "_" + j,PMSI.DepthManager.getNextDepth());
- checkbox = mcon.attachMovie("radiobutton","check_" + i + "_" + j,PMSI.DepthManager.getNextDepth());
- answerList.push(checkbox);
- checkbox.feedbackCheck = feedbackCheck;
- checkbox.onRelease = answerOnRelease;
- checkbox.groupId = i;
- if(answerText.text == ai.questions.question[i].correctAnswer.text)
- {
- checkbox.isCorrectAnswer = true;
- }
- else
- {
- checkbox.isCorrectAnswer = false;
- }
- answer = createAnswerField(mcon,j,0,answerText);
- qtr = new TableRow();
- qtc = new TableCell(feedbackCheck);
- qtr.addCell(qtc);
- qtc = new TableCell(checkbox);
- qtr.addCell(qtc);
- qtc = new TableCell(answer);
- qtr.addCell(qtc);
- atables[i].addRow(qtr);
- j++;
- }
- i++;
- }
- trace("tableY: " + tableY);
- var tableWidth = layoutinfo.MAX_WIDTH - rightSideBuffer;
- trace("layoutinfo.MAX_WIDTH: " + layoutinfo.MAX_WIDTH);
- trace("rightSideBuffer " + rightSideBuffer);
- trace("TABLE WIDTH: " + tableWidth);
- var ttab;
- var atab;
- var tableY1 = tableY;
- var tableY2 = tableY;
- var maxHeight = 0;
- var divsor = atables.length <= 3 ? 1 : 2;
- var i = 0;
- while(i < tables.length)
- {
- trace("i: " + i);
- ttab = tables[i];
- ttab.setPosition({x:0,y:0});
- ttab.setCellSpacing(6);
- ttab.init();
- ttab.setWidth(tableWidth / divsor);
- trace(ttab.height);
- tableY1 += ttab.height;
- trace("ASDA: " + ttab.width);
- atab = atables[i];
- atab.setPosition({x:0,y:ttab.height + 4});
- atab.setCellSpacing(6);
- atab.init();
- atab.setWidth(tableWidth / divsor);
- trace(atab.height);
- tableY1 += atab.height - 30;
- if(maxHeight < ttab.height + atab.height)
- {
- maxHeight = ttab.height + atab.height;
- }
- trace("maxHeight: " + maxHeight);
- i++;
- }
- biglayout = new TableClass();
- qtr = new TableRow();
- qtc = new TableCell(qcon0);
- qtr.addCell(qtc);
- qtc = new TableCell(qcon1);
- qtr.addCell(qtc);
- biglayout.addRow(qtr);
- qtr = new TableRow();
- qtc = new TableCell(qcon2);
- qtr.addCell(qtc);
- qtc = new TableCell(qcon3);
- qtr.addCell(qtc);
- biglayout.addRow(qtr);
- qtr = new TableRow();
- qtc = new TableCell(qcon4);
- qtr.addCell(qtc);
- qtc = new TableCell(qcon5);
- qtr.addCell(qtc);
- biglayout.addRow(qtr);
- biglayout.setPosition({x:layoutInfo.box.x,y:tableY});
- biglayout.setCellSpacing(20);
- biglayout.init();
- }
- function answerOnRollOver()
- {
- this.gotoAndStop("rollOver");
- }
- function answerOnRollOut()
- {
- this.gotoAndStop("rollOut");
- }
- function answerOnRelease()
- {
- if(this._parent._parent.isMulti)
- {
- var groupId = this.groupId;
- var gmem;
- var i = 0;
- while(true)
- {
- gmem = this._parent["check_" + groupId + "_" + i];
- if(gmem == null)
- {
- break;
- }
- trace(gmem);
- if(gmem != this)
- {
- gmem.gotoAndStop("notSelected");
- gmem.isSelected = false;
- }
- i++;
- }
- }
- trace(this + ": " + this.isSelected);
- if(!this.isSelected || this.isSelected == null)
- {
- this.isSelected = true;
- this.gotoAndStop("selected");
- }
- else
- {
- this.isSelected = false;
- this.gotoAndStop("notSelected");
- }
- }
- function createInstructionField(cnt, name, text)
- {
- var mc = cnt.createEmptyMovieClip(name,PMSI.DepthManager.getNextDepth());
- mc.createTextField("content",PMSI.DepthManager.getNextDepth(),0,0,0,0);
- var tf = layoutInfo.instTextFormat;
- mc.content.embedFonts = true;
- mc.content.border = false;
- mc.content.type = "dynamic";
- mc.content.text = text;
- mc.content.setTextFormat(tf);
- mc.content._height = 400;
- mc.content.wordWrap = true;
- mc.content.color = layoutInfo.instTextColor;
- mc.content._width = 300;
- mc.content.autoSize = true;
- mc.content.selectable = false;
- return mc;
- }
- function createQuestionField(cnt, id, text)
- {
- var mc = cnt.createEmptyMovieClip("question" + id,PMSI.DepthManager.getNextDepth());
- mc.createTextField("content",PMSI.DepthManager.getNextDepth(),0,0,0,0);
- var tf = layoutInfo.qTextFormat;
- mc.content.embedFonts = true;
- mc.content.border = TXT_DEBUG_SHOW_BORDERS;
- mc.content.type = "dynamic";
- mc.content.text = text;
- mc.content.autoSize = true;
- mc.content.setTextFormat(tf);
- mc.content.selectable = false;
- return mc;
- }
- function createAnswerField(cnt, id, subid, text)
- {
- var amc1 = cnt.createEmptyMovieClip("answer" + subid + "_" + id,PMSI.DepthManager.getNextDepth());
- amc1.createTextField("content",PMSI.DepthManager.getNextDepth(),0,0,0,0);
- var tf2 = layoutInfo.answerTextFormat1;
- amc1.content.embedFonts = true;
- amc1.content.border = TXT_DEBUG_SHOW_BORDERS;
- amc1.content.type = "dynamic";
- amc1.content.text = text;
- amc1.content.autoSize = true;
- amc1.content.selectable = false;
- amc1.content.setTextFormat(tf2);
- return amc1;
- }
- function createAnswerSpacer(cnt, id)
- {
- var amcSpacer = cnt.createEmptyMovieClip("answerSpacer_" + id,PMSI.DepthManager.getNextDepth());
- amcSpacer.createTextField("content",PMSI.DepthManager.getNextDepth(),0,0,0,0);
- var tf2 = layoutInfo.answerTextFormat1;
- amcSpacer.content.embedFonts = true;
- amcSpacer.content.border = TXT_DEBUG_SHOW_BORDERS;
- amcSpacer.content.type = "dynamic";
- amcSpacer.content.text = " ";
- amcSpacer.content.autoSize = true;
- amcSpacer.content.setTextFormat(tf2);
- amcSpacer.content.selectable = false;
- return amcSpacer;
- }
- function checkAnswers()
- {
- var qlen = ai.questions.question.length;
- var correct = 0;
- var clp;
- var i = 0;
- while(i < answerList.length)
- {
- clp = answerList[i];
- if(clp.isSelected && clp.isCorrectAnswer)
- {
- correct++;
- clp.feedbackCheck.gotoAndStop("correct");
- }
- else if(clp.isSelected && !clp.isCorrectAnswer)
- {
- clp.feedbackCheck.gotoAndStop("incorrect");
- }
- else
- {
- clp.feedbackCheck.gotoAndStop(1);
- }
- i++;
- }
- master.setFeedback(correct,qlen);
- }
- function createTitleField(txt)
- {
- var mc = this.createEmptyMovieClip("title",PMSI.DepthManager.getNextDepth());
- mc.createTextField("content",PMSI.DepthManager.getNextDepth(),0,0,0,0);
- var tf = layoutInfo.titleTextFormat;
- mc.content.embedFonts = true;
- mc.content.border = false;
- mc.content.type = "dynamic";
- mc.content.text = txt;
- mc.content.setTextFormat(tf);
- mc.content.wordWrap = true;
- mc.content.color = layoutInfo.instTextColor;
- mc.content._width = 300;
- mc.content.autoSize = true;
- mc.content.selectable = false;
- return mc;
- }
- function highlightIncorrect(text)
- {
- }
- function clearClip()
- {
- layoutInfo.qMaxWidthPos = 0;
- layoutInfo.qMaxWidth = 0;
- layoutInfo.a1MaxWidth = 0;
- layoutInfo.a2MaxWidth = 0;
- for(var mc in this)
- {
- if(this[mc] != _parent && this[mc] != this)
- {
- this[mc].clear();
- this[mc].removeMovieClip();
- }
- }
- }
- function drawDebugBox()
- {
- this.lineStyle(1,16711680,100);
- this.drawRect(layoutInfo.box.x,layoutInfo.box.y,layoutInfo.MAX_WIDTH,layoutInfo.MAX_HEIGHT);
- }
- function replaceBlanks(s_str, maxlen)
- {
- trace("MAXLEN: " + maxlen);
- var str = s_str.toString();
- return replaceBlanksR(str,maxlen);
- }
- function replaceBlanksR(s_str, maxlen)
- {
- trace(s_str);
- var si = s_str.indexOf(TAGS.BLANK_OPEN);
- if(si == -1)
- {
- return s_str;
- }
- var ei = s_str.indexOf(TAGS.BLANK_CLOSE) + TAGS.BLANK_CLOSE.length;
- s_str = s_str.slice(0,si) + makeStringFromChar("_",maxlen) + s_str.slice(ei,s_str.length);
- return replaceBlanks(s_str,maxlen);
- }
- function makeStringFromChar(char, length)
- {
- var str = "";
- var i = 0;
- while(i < length)
- {
- str += char;
- i++;
- }
- return str;
- }
- stop();
- var TXT_DEBUG_SHOW_BORDERS = false;
- var testFile1 = "activities/data/C1.U2.S3.EV.VA.7.xml";
- var testFile2 = "C1.U2.S3.VO.1.B2.xml";
- var testFile3 = "C1.U1.S2.GR.3.A1.xml";
- if(_parent)
- {
- master = _parent;
- }
- else
- {
- master = this;
- }
- if(master.layoutInfo == null)
- {
- var layoutInfo = {};
- layoutInfo.titleTextColor = 3636920;
- layoutInfo.answerRollOverColor = 16695085;
- layoutInfo.answerRollOutColor = 3636920;
- layoutInfo.answerSelectColor = 2309272;
- layoutInfo.questionTextColor = 2309272;
- layoutInfo.instTextColor = 2309272;
- layoutInfo.doAnswerFill = false;
- layoutInfo.rightSideBuffer = 60;
- layoutInfo.box = {};
- layoutInfo.box.x = 260;
- layoutInfo.box.y = 94;
- layoutInfo.box.views = [];
- layoutInfo.box.widthWithBox = 300;
- layoutInfo.box.heightWithBox = 300;
- layoutInfo.box.widthWithoutBox = 300;
- layoutInfo.box.heightWithoutBox = 300;
- layoutinfo.MAX_WIDTH = 520;
- layoutInfo.MAX_HEIGHT = 380;
- layoutInfo.questionIndent = 30;
- layoutInfo.selectionRadius = 6;
- layoutInfo.drawSelectionCircle = true;
- layoutInfo.lineSpacing = 5;
- layoutInfo.selectionBorderThickness = 1;
- layoutInfo.instTextFormat = new TextFormat();
- layoutInfo.instTextFormat.font = "Formata_Bold";
- layoutInfo.instTextFormat.size = 12;
- layoutInfo.instTextFormat.color = layoutInfo.instTextColor;
- layoutInfo.qTextFormat = new TextFormat();
- layoutInfo.qTextFormat.font = "Formata_Normal";
- layoutInfo.qTextFormat.size = 12;
- layoutInfo.qTextFormat.color = layoutInfo.questionTextColor;
- layoutInfo.qTextFormat.align = "right";
- layoutInfo.answerTextFormat1 = new TextFormat();
- layoutInfo.answerTextFormat1.font = "Formata_Normal";
- layoutInfo.answerTextFormat1.size = 12;
- layoutInfo.answerTextFormat1.color = layoutInfo.answerRollOutColor;
- layoutInfo.answerTextFormat2 = new TextFormat();
- layoutInfo.answerTextFormat2.font = "Formata_Normal";
- layoutInfo.answerTextFormat2.size = 12;
- layoutInfo.answerTextFormat2.color = layoutInfo.answerRollOutColor;
- layoutInfo.titleTextFormat = new TextFormat();
- layoutInfo.titleTextFormat.font = "TriplexCondSerifBlack";
- layoutInfo.titleTextFormat.size = 24;
- layoutInfo.titleTextFormat.color = layoutInfo.titleTextColor;
- }
- else
- {
- layoutInfo = master.layoutInfo;
- }
- layoutInfo.temp4InstWidth = 250;
- layoutInfo.temp4InstY = 305;
- var ai = new ActivityInfo();
- ai._parent = this;
- ai.onLoad = function(success)
- {
- trace("id: " + this.getIdString());
- trace("type: " + this.type);
- var i = 0;
- while(i < this.questions.question.length)
- {
- trace(i + 1 + ". " + this.questions.question[i].questionText);
- i++;
- }
- this._parent.render();
- trace("Time: " + (getTimer() - t) / 1000);
- };
- if(_parent == null)
- {
- loadActivity(testFile1);
- }
- answer.onRelease = function()
- {
- checkAnswers();
- };
- answer.onRollOver = function()
- {
- this.gotoAndStop("rollOver");
- };
- answer.onRollOut = function()
- {
- this.gotoAndStop("rollOut");
- };
- TAGS = {};
- TAGS.BLANK_OPEN = "[:blank:]";
- TAGS.BLANK_CLOSE = "[:/blank:]";
-